<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/import.jsp" %>
<%@ taglib uri="/WEB-INF/privilege" prefix="p"%>
<html>
  <head>
     <style type="text/css">
     </style>
  </head>
  <body scroll="no">
  <script type="text/javascript">
       jQuery.ajaxSetup({cache: false});
       $(function(){
    	   $("#roleTable").datagrid({
    		   //width: 600,
    		   nowrap: false,
    		   triped: false,
    		   fitColumns: true,
    		   url: '${ctx}/sys/role/list.do',
    		   columns: [[
    		             {field: 'ck', checkbox: true},
    		             {field: 'roleName', title: '角色名称', width: 100, align: 'center'},
    		             {field: 'createUser', title: '创建者', width: 100, align: 'center'},
    		             {field: 'createTime', title: '创建时间', width: 100, align: 'center'},
    		             {field: 'updateTime', title: '更新时间', width: 100, align: 'center'},
    		             {field: 'remark', title: '备注', width: 100, align: 'center'}
    		            ]],
    		   pagination: true,
    		   rownumbers: true,
    		   pageSize: 20,
    		   pageList: pageList
    	   });
       });
       
       function add(href){
    	   showWindow("添加角色", href);
    	   return false;
       }
       function edit(href){
    	   var node = getSelectedRows();
    	   if (node&&node.length==1){
    		   showWindow("修改角色", href+"?id="+node[0].id);
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function del(href){
    	   var rows = getSelectedRows();
    	   if (rows&&rows.length > 0){
    		   deleteConfirm(function(){
    			   var ps = "";
		           $.each(rows,function(i,n){
		        	   if(i==0) 
		        			ps += n.id;
		        		else
		        			ps += ","+n.id;
		        	});
		           $.blockUI();
    			   $.ajax({
		    			  url: href,   // 提交的页面
		    		      data: {ids: ps}, 
		    		      type: "POST",
		    		      success: function(data) {
		    		    	  $.unblockUI();
		    		        	if(data.success==true){
		    		        		showSuccessMsg();
		    		        		reloadGrid();
		    		        	}else{
		    		        		showFailAlert()
		    		        	}
		    		      },
		    		      error: function(xhr) {
		    		    	  $.unblockUI();
		    		    	  showFailAlert2(xhr);
		    		      }
		    		  })
    		   });
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function view(href){
    	   var node = getSelectedRows();
    	   if (node&&node.length==1){
    		   showWindow("查看角色", href+"?id="+node[0].id);
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function accredit(href){
    	   var node = getSelectedRows();
    	   if (node&&node.length==1){
    		   showWindow("授权角色", href+"?id="+node[0].id);
    	   }else{
    		   showAlertMsg();
    	   }
    	   return false;
       }
       function reloadGrid(){
    	   $("#roleTable").datagrid("reload");
       }
       function loadGrid(){
    	   $("#roleTable").datagrid("load");
       }
       function getSelectedRows(){
    	   var rows = $('#roleTable').datagrid('getSelections');
    	   return rows;
       }
       function queryForm(){
    	   var params = $('#roleTable').datagrid('options').queryParams; //先取得 datagrid 的查询参数
    	   var fields =$('#queryRoleForm').serializeArray(); //自动序列化表单元素为JSON对象
    	   $.each( fields, function(i, field){
    		   params[field.name] = field.value; //设置查询参数
           });   
    	   loadGrid();
       }
       function clearForm(){
    	   $('#queryRoleForm').form('clear');
    	   queryForm();
       }
    </script>
    <div class="easyui-layout" data-options="fit:true">
    <div region="north" style="overflow-y: hidden; overflow-x: hidden" border="false">
        <form id="queryRoleForm" onSubmit="queryForm();return false;">
	        <table width="99.5%" style="padding-left: 5px;">
		        <td width="50px">角色名称</td><td width="60px"><input id="roleName" type="text" name="roleName" value="" ></td>
			    <td width="85px"><a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="queryForm();">查询</a></td>
			    <td><a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="clearForm();">重置</a></td>
			</table>
        </form>
		<div class="btabs">
		    <p:op code="sysRoleAdd">
				<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/role/toAdd.do" 
				onclick="return add(this.href);"><span class="icon icon-add">&nbsp;</span>添加</a>
		    </p:op>
		    <p:op code="sysRoleEdit">
				<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/role/toAdd.do" 
				onclick="return edit(this.href);"><span class="icon icon-edit">&nbsp;</span>修改</a>
			</p:op>
		    <p:op code="sysRoleDel">
				<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/role/delete.do" 
				onclick="return del(this.href);"><span class="icon icon-delete">&nbsp;</span>删除</a>
			</p:op>
		    <p:op code="sysRoleView">
				<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/role/toView.do" 
				onclick="return view(this.href);"><span class="icon icon-view">&nbsp;</span>查看</a>
			</p:op>
		    <p:op code="sysRoleAccredit">
				<a class="easyui-linkbutton" data-options="plain:true" href="${ctx}/sys/role/toAccredit.do" 
				onclick="return accredit(this.href);"><span class="icon icon-accredit">&nbsp;</span>授权</a> 
			</p:op>
		</div>
    </div>
    <div region="center" style="padding: 1px;" border="false">
       <table id="roleTable" fit="true" ></table>
    </div>
    </div>
  </body>
</html>
